package com.ruoyi.project.app.controller;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.project.app.util.XResult;
import com.ruoyi.project.beautyflower.commodity.domain.Commodity;
import com.ruoyi.project.beautyflower.commodity.service.ICommodityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;

/**
 * 商品模块
 */
@RestController
@RequestMapping("/app/commodity")
@Api(tags = "商品模块 ")
public class AppCommodityController extends BaseController {

    @Autowired
    private ICommodityService commodityService;
    /**
     * 上线商品数据
     * @return
     */
    @PostMapping("selectCommodityList")
    @ApiOperation(notes = "selectCommodityList", value = "查询商品数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pageSize", value = "当前显示数据条数", required = false, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "name", value = "商品名称", required = false, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "商品类型(1：推荐商品2:不是推荐商品，3：所有商品)", required = false, paramType = "query", dataType = "String"),

    })
    public Object selectCommodityList(@ApiIgnore HttpServletRequest request)  {
        Commodity commodity= new Commodity();
        if(StringUtils.isNotBlank(request.getParameter("name"))){
            commodity.setName(request.getParameter("name"));
        }
        if(StringUtils.isNotBlank(request.getParameter("type"))){
            if(request.getParameter("type").equals("3")){
                commodity.setKnown(null);
            }else{
                commodity.setKnown(Integer.parseInt(request.getParameter("type")));
            }
        }
        startPage();
        return new XResult("查询成功", getDataTable(commodityService.selectCommodityList(commodity)));
    }

}
